package com.txunda.zhuohired.adapter.user.resume;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.bean.common.CommonEducationListBean;

import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/8 11:12
 * 功能描述：在线预览教育经历adapter
 * 联系方式：jiahuanchen@126.com
 */

public class PreviewEducationAdapter extends BaseAdapter {
    private Context context;
    private ViewHolder holder;
    private List<CommonEducationListBean> educationList;

    public PreviewEducationAdapter(Context context, List<CommonEducationListBean> educationList) {
        this.context = context;
        this.educationList = educationList;
    }

    @Override
    public int getCount() {
        return educationList.size();
    }

    @Override
    public Object getItem(int i) {
        return educationList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_preview_education, null);
            holder = new ViewHolder();
            view.setTag(holder);
            ViewUtils.inject(holder, view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        if (TextUtils.isEmpty(educationList.get(i).getSchool_name())) {
            holder.tv_preview_education_name.setVisibility(View.GONE);
        } else {
            holder.tv_preview_education_name.setVisibility(View.VISIBLE);
            holder.tv_preview_education_name.setText(educationList.get(i).getSchool_name());
        }

        if (TextUtils.isEmpty(educationList.get(i).getTime())) {
            holder.tv_preview_education_time.setVisibility(View.GONE);
        } else {
            holder.tv_preview_education_time.setVisibility(View.VISIBLE);
            holder.tv_preview_education_time.setText(educationList.get(i).getTime());
        }

        if (TextUtils.isEmpty(educationList.get(i).getProfession_name()) && TextUtils.isEmpty(educationList.get(i)
                .getEducation_name())) {
            holder.tv_preview_education_major.setVisibility(View.GONE);
        } else {
            holder.tv_preview_education_major.setVisibility(View.VISIBLE);
            holder.tv_preview_education_major.setText(educationList.get(i).getProfession_name() + "|" + educationList
                    .get(i).getEducation_name());
        }

        return view;
    }

    class ViewHolder {
        /**
         * 学校名称
         */
        @ViewInject(R.id.tv_preview_education_name)
        private TextView tv_preview_education_name;
        /**
         * 时间
         */
        @ViewInject(R.id.tv_preview_education_time)
        private TextView tv_preview_education_time;
        /**
         * 专业|学历
         */
        @ViewInject(R.id.tv_preview_education_major)
        private TextView tv_preview_education_major;
    }
}
